<?php

namespace app\common\model;
use think\Db;
/**
 * [资讯分类表]
 * @author [C。]
 * @return html
 */
class Cate extends Base
{
    protected $name = 'cate';
    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getlist($map,$from = 0, $size = 5)
    {
        $order = ['n.id' => 'desc'];
        $join = [
            ['app_news n','n.cateid = z.id'],
        ];
        $result =  $this->field('z.cname,n.id,n.title,n.cover,n.addtime')
            ->alias('z')
            ->join($join)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }

    /**
     * 搜索获取寺院列表总数
     * @param array $param
     */
    public function getCount($map) {
        $join = [
            ['app_news n','n.cateid = z.id'],
        ];
        $result =  $this->alias('z')
            ->join($join)
            ->where($map)
            ->count();

        return $result;
    }

    /**
     * 根据条件获取相应字段
     * @param array $param
     */
    public function getConditionByFields($map,$field='*') {
        $order = ['sort' => 'asc'];
        $result = $this->field($field)->where($map)->order($order)->select()->toArray();
        return $result;
    }
}